﻿using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Assist;
using YArchitech.LIB;
using HYFamilyLibDataManager;

namespace HYRElectric.Calculate
{
	public partial class DlgColumnModify : System.Windows.Forms.Form
	{
		public DlgColumnModify()
		{
			this.InitializeComponent();
		}

		public DlgColumnModify(SqliteElectricDatabase db)
		{
			this.dbIllAndPower = db;
			this.InitializeComponent();
			this.m_MultiData = new DGVRowData();
			this.InitCmbQFSXS();
			this.InitCmbDMFSXS();
			this.BindEvent();
		}

		private void BindEvent()
		{
			this.chkKJGD.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkGZMGD.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkAZGD.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkDPFSXS.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkSBFSXS.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkXBFSXS.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkDMFSXS.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkCFSXS.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkPJZD.CheckedChanged += this.checkbox_CheckedChanged;
			this.chkYQGLMD.CheckedChanged += this.checkbox_CheckedChanged;
		}

		private void checkbox_CheckedChanged(object sender, EventArgs e)
		{
			CheckBox checkBox = sender as CheckBox;
			string name = checkBox.Name;
			uint num = 0;//<PrivateImplementationDetails>.ComputeStringHash(name);
			if (num <= 1142220642u)
			{
				if (num <= 46630715u)
				{
					if (num != 643044u)
					{
						if (num != 46630715u)
						{
							return;
						}
						if (!(name == "chkYQGLMD"))
						{
							return;
						}
						this.BindEvent(checkBox, this.btnYQGLMD);
						this.BindEvent(checkBox, this.tbYQGLMD);
					}
					else
					{
						if (!(name == "chkSBFSXS"))
						{
							return;
						}
						this.BindEvent(checkBox, this.cmbSBFSXS);
						return;
					}
				}
				else if (num != 383636507u)
				{
					if (num != 1046854021u)
					{
						if (num != 1142220642u)
						{
							return;
						}
						if (!(name == "chkGZMGD"))
						{
							return;
						}
						this.BindEvent(checkBox, this.tbGZMGD);
						return;
					}
					else
					{
						if (!(name == "chkDPFSXS"))
						{
							return;
						}
						this.BindEvent(checkBox, this.cmbDPFSXS);
						return;
					}
				}
				else
				{
					if (!(name == "chkPJZD"))
					{
						return;
					}
					this.BindEvent(checkBox, this.btnYQZD);
					this.BindEvent(checkBox, this.tbPJZD);
					return;
				}
			}
			else if (num <= 2521416386u)
			{
				if (num != 1673654483u)
				{
					if (num != 2521416386u)
					{
						return;
					}
					if (!(name == "chkCFSXS"))
					{
						return;
					}
					this.BindEvent(checkBox, this.tbCFSXS);
					return;
				}
				else
				{
					if (!(name == "chkXBFSXS"))
					{
						return;
					}
					this.BindEvent(checkBox, this.cmbXBFSXS);
					return;
				}
			}
			else if (num != 3061183666u)
			{
				if (num != 3681714451u)
				{
					if (num == 4258356513u)
					{
						if (!(name == "chkKJGD"))
						{
							return;
						}
						this.BindEvent(checkBox, this.tbKJGD);
						return;
					}
				}
				else
				{
					if (!(name == "chkAZGD"))
					{
						return;
					}
					this.BindEvent(checkBox, this.tbAZGD);
					return;
				}
			}
			else
			{
				if (!(name == "chkDMFSXS"))
				{
					return;
				}
				this.BindEvent(checkBox, this.cmbDMFSXS);
				return;
			}
		}

		private void BindEvent(CheckBox chk, Control ctl)
		{
			if (chk.Checked)
			{
				ctl.Enabled = true;
				return;
			}
			ctl.Enabled = false;
		}

		private void DlgColumnModify_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private void btnYQZD_Click(object sender, EventArgs e)
		{
			using (DlgSelIllAndPower dlgSelIllAndPower = new DlgSelIllAndPower(this.dbIllAndPower))
			{
				if (dlgSelIllAndPower.ShowDialog() == DialogResult.OK)
				{
					this.tbPJZD.Text = dlgSelIllAndPower.m_IllAndPowerData.dZDBZ.ToString();
					this.tbYQGLMD.Text = dlgSelIllAndPower.m_IllAndPowerData.dXXZ.ToString();
					this.m_MultiData.dPJZD = dlgSelIllAndPower.m_IllAndPowerData.dZDBZ;
					this.m_MultiData.dYQGLMD = dlgSelIllAndPower.m_IllAndPowerData.dXXZ;
					this.m_MultiData.sJZWLX = dlgSelIllAndPower.m_IllAndPowerData.sJZWLX;
					this.m_MultiData.sCSLX = dlgSelIllAndPower.m_IllAndPowerData.sCSLX;
				}
			}
		}

		private void btnYQGLMD_Click(object sender, EventArgs e)
		{
			using (DlgSelIllAndPower dlgSelIllAndPower = new DlgSelIllAndPower(this.dbIllAndPower))
			{
				if (dlgSelIllAndPower.ShowDialog() == DialogResult.OK)
				{
					this.tbPJZD.Text = dlgSelIllAndPower.m_IllAndPowerData.dZDBZ.ToString();
					this.tbYQGLMD.Text = dlgSelIllAndPower.m_IllAndPowerData.dXXZ.ToString();
					this.m_MultiData.dPJZD = dlgSelIllAndPower.m_IllAndPowerData.dZDBZ;
					this.m_MultiData.dYQGLMD = dlgSelIllAndPower.m_IllAndPowerData.dXXZ;
					this.m_MultiData.sJZWLX = dlgSelIllAndPower.m_IllAndPowerData.sJZWLX;
					this.m_MultiData.sCSLX = dlgSelIllAndPower.m_IllAndPowerData.sCSLX;
				}
			}
		}

		private void InitCmbQFSXS()
		{
			this.cmbDPFSXS.Items.Clear();
			this.cmbXBFSXS.Items.Clear();
			this.cmbSBFSXS.Items.Clear();
			DataTable dataTable = this.dbIllAndPower.ExecQuery("select [RefFactor], [Describe] from [CeilingRef]");
			if (dataTable != null)
			{
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					FSXSData fsxsdata = new FSXSData();
					fsxsdata.sDescribe = dataTable.Rows[i][1].ToString() + " :" + dataTable.Rows[i][0].ToString();
					fsxsdata.dValue = Convert.ToDouble(dataTable.Rows[i][0].ToString());
					this.cmbDPFSXS.Items.Add(fsxsdata);
					this.cmbXBFSXS.Items.Add(fsxsdata);
					this.cmbSBFSXS.Items.Add(fsxsdata);
				}
			}
			if (this.cmbDPFSXS.Items.Count > 0)
			{
				this.cmbDPFSXS.SelectedIndex = 0;
				this.m_MultiData.dDPFSXS = (FSXSData)this.cmbDPFSXS.SelectedItem;
			}
			if (this.cmbXBFSXS.Items.Count > 0)
			{
				this.cmbXBFSXS.SelectedIndex = 0;
				this.m_MultiData.dXBFSXS = (FSXSData)this.cmbXBFSXS.SelectedItem;
			}
			if (this.cmbSBFSXS.Items.Count > 0)
			{
				this.cmbSBFSXS.SelectedIndex = 0;
				this.m_MultiData.dSBFSXS = (FSXSData)this.cmbSBFSXS.SelectedItem;
			}
		}

		private void InitCmbDMFSXS()
		{
			this.cmbDMFSXS.Items.Clear();
			DataTable dataTable = this.dbIllAndPower.ExecQuery("select [RefFactor], [Describe] from [GroundRef]");
			if (dataTable != null)
			{
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					FSXSData fsxsdata = new FSXSData();
					fsxsdata.sDescribe = dataTable.Rows[i][1].ToString() + " :" + dataTable.Rows[i][0].ToString();
					fsxsdata.dValue = Convert.ToDouble(dataTable.Rows[i][0].ToString());
					this.cmbDMFSXS.Items.Add(fsxsdata);
				}
			}
			if (this.cmbDMFSXS.Items.Count > 0)
			{
				this.cmbDMFSXS.SelectedIndex = 0;
				this.m_MultiData.dDMFSXS = (FSXSData)this.cmbDMFSXS.SelectedItem;
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			double num = 0.0;
			if (this.chkKJGD.Checked)
			{
				if (string.IsNullOrEmpty(this.tbKJGD.Text))
				{
					MessageBox.Show(this.chkKJGD.Text + "不能为空！", "盈建科提示");
					this.chkKJGD.Focus();
					return;
				}
				if (!double.TryParse(this.tbKJGD.Text, out num))
				{
					MessageBox.Show(this.chkKJGD.Text + "输入不合法，请重新输入！", "盈建科提示");
					this.chkKJGD.Focus();
					return;
				}
				this.m_MultiData.dFJGD = Convert.ToDouble(this.tbKJGD.Text);
			}
			if (this.chkAZGD.Checked)
			{
				if (string.IsNullOrEmpty(this.tbAZGD.Text))
				{
					MessageBox.Show(this.chkAZGD.Text + "不能为空！", "盈建科提示");
					this.tbAZGD.Focus();
					return;
				}
				if (!double.TryParse(this.tbAZGD.Text, out num))
				{
					MessageBox.Show(this.chkAZGD.Text + "输入不合法，请重新输入！", "盈建科提示");
					this.tbAZGD.Focus();
					return;
				}
				this.m_MultiData.dAZGD = Convert.ToDouble(this.tbAZGD.Text);
			}
			if (this.chkCFSXS.Checked)
			{
				if (string.IsNullOrEmpty(this.tbCFSXS.Text))
				{
					MessageBox.Show(this.chkCFSXS.Text + "不能为空！", "盈建科提示");
					this.tbCFSXS.Focus();
					return;
				}
				if (!double.TryParse(this.tbCFSXS.Text, out num))
				{
					MessageBox.Show(this.chkCFSXS.Text + "输入不合法，请重新输入！", "盈建科提示");
					this.tbCFSXS.Focus();
					return;
				}
				this.m_MultiData.dCFSXS = Convert.ToDouble(this.tbCFSXS.Text);
			}
			if (this.chkGZMGD.Checked)
			{
				if (string.IsNullOrEmpty(this.tbGZMGD.Text))
				{
					MessageBox.Show(this.chkGZMGD.Text + "不能为空！", "盈建科提示");
					this.tbGZMGD.Focus();
					return;
				}
				if (!double.TryParse(this.tbGZMGD.Text, out num))
				{
					MessageBox.Show(this.chkGZMGD.Text + "输入不合法，请重新输入！", "盈建科提示");
					this.tbGZMGD.Focus();
					return;
				}
				this.m_MultiData.dGZMGD = Convert.ToDouble(this.tbGZMGD.Text);
			}
			if (this.cmbDPFSXS.SelectedIndex >= 0 && this.chkDPFSXS.Checked)
			{
				this.m_MultiData.dDPFSXS = (FSXSData)this.cmbDPFSXS.SelectedItem;
			}
			if (this.cmbSBFSXS.SelectedIndex >= 0 && this.chkSBFSXS.Checked)
			{
				this.m_MultiData.dSBFSXS = (FSXSData)this.cmbSBFSXS.SelectedItem;
			}
			if (this.cmbXBFSXS.SelectedIndex >= 0 && this.chkXBFSXS.Checked)
			{
				this.m_MultiData.dXBFSXS = (FSXSData)this.cmbXBFSXS.SelectedItem;
			}
			if (this.cmbDMFSXS.SelectedIndex >= 0 && this.chkDMFSXS.Checked)
			{
				this.m_MultiData.dDMFSXS = (FSXSData)this.cmbDMFSXS.SelectedItem;
			}
			if (this.chkPJZD.Checked)
			{
				if (string.IsNullOrEmpty(this.tbPJZD.Text))
				{
					MessageBox.Show(this.chkPJZD.Text + "不能为空！", "盈建科提示");
					this.tbPJZD.Focus();
					return;
				}
				if (!double.TryParse(this.tbPJZD.Text, out num))
				{
					MessageBox.Show(this.chkPJZD.Text + "输入不合法，请重新输入！", "盈建科提示");
					this.tbPJZD.Focus();
					return;
				}
				this.m_MultiData.dPJZD = Convert.ToDouble(this.tbPJZD.Text.Trim());
			}
			if (this.chkYQGLMD.Checked)
			{
				if (string.IsNullOrEmpty(this.tbYQGLMD.Text))
				{
					MessageBox.Show(this.chkYQGLMD.Text + "不能为空！", "盈建科提示");
					this.tbYQGLMD.Focus();
					return;
				}
				if (!double.TryParse(this.tbYQGLMD.Text, out num))
				{
					MessageBox.Show(this.chkYQGLMD.Text + "输入不合法，请重新输入！", "盈建科提示");
					this.tbYQGLMD.Focus();
					return;
				}
				this.m_MultiData.dYQGLMD = Convert.ToDouble(this.tbYQGLMD.Text.Trim());
			}
			base.DialogResult = DialogResult.OK;
		}

		private void tbAZGD_Leave(object sender, EventArgs e)
		{
			TextBox txt = sender as TextBox;
			string msg = "安装高度必须小于或等于空间高度，请重新修改！";
			this.ValidGZGD(txt, msg);
		}

		private void ValidGZGD(TextBox txt, string msg)
		{
			if (!string.IsNullOrEmpty(this.tbAZGD.Text.Trim()) && !string.IsNullOrEmpty(this.tbKJGD.Text.Trim()) && Convert.ToDouble(this.tbAZGD.Text.Trim()) > Convert.ToDouble(this.tbKJGD.Text.Trim()))
			{
				MessageBox.Show(msg, "盈建科提示");
				txt.Focus();
			}
		}

		private void tbKJGD_Leave(object sender, EventArgs e)
		{
			TextBox txt = sender as TextBox;
			string msg = "空间高度必须大于或等于安装高度，请重新修改！";
			this.ValidGZGD(txt, msg);
		}

		private void Validata(string txt, KeyPressEventArgs e)
		{
			if (e.KeyChar == ' ')
			{
				e.Handled = true;
				return;
			}
			if (e.KeyChar == '\b')
			{
				return;
			}
			double num = 0.0;
			if (!double.TryParse(txt + e.KeyChar.ToString(), out num))
			{
				e.Handled = true;
				return;
			}
			if (num > 0.0)
			{
				e.Handled = false;
				return;
			}
			e.Handled = true;
		}

		private void tbKJGD_KeyPress(object sender, KeyPressEventArgs e)
		{
			TextBox textBox = sender as TextBox;
			this.Validata(textBox.Text.Trim(), e);
		}

		public DGVRowData m_MultiData;

		private SqliteElectricDatabase dbIllAndPower;
	}
}
